package leetcode.editor.cn.q1xx

import java.util.*
import kotlin.math.min

class Q155 {
    private val stack = LinkedList<Int>()
    private val minValueStack = LinkedList<Int>()

    fun push(x: Int) {
        stack.push(x)
        if (minValueStack.isEmpty()) {
            minValueStack.push(x)
        } else {
            minValueStack.push(min(minValueStack.peek(), x))
        }
    }

    fun pop() {
        minValueStack.pop()
        stack.pop()
    }

    fun top(): Int {
        return stack.peek()
    }

    fun getMin(): Int {
        return minValueStack.peek()
    }
}